package com.hist.medical_treatment.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import com.hist.medical_treatment.entity.User;

@Mapper
public interface UserDao {
	@Select("select user.ID,UserName,RealName,UseType,constantitem.ConstantName,IsScheduling,department.DeptName,registlevel.RegistName from user,constantitem,department,registlevel where user.DocTitleID=constantitem.ID and user.DeptID=department.ID and user.RegistLeID=registlevel.ID")
    List<User> getUser();
	@Delete("delete from user where ID=#{id}")
	void deleteUserByID(Integer id);
	@Update("update user set UserName=#{userName},RealName=#{realName},UseType=#{useType},DocTitleID=#{docTitleId},IsScheduling=#{isScheduling},DeptID=#{deptId},RegistLeID=#{registLeId} where ID=#{id}")
	void updateUserByID(Integer id,String userName,String realName,Integer useType,Integer docTitleId,String isScheduling,Integer deptId,Integer registLeId);
    @Select("select ID from constantitem where ConstantName=#{constantName}")
    Integer getIDByConstantName(String constantName);
    @Select("select ID from department where DeptName=#{deptName}")
    Integer getIDByDeptName(String deptName);
    @Select("select ID from registlevel where RegistName=#{registName}")
    Integer getIDByRegistName(String registName);
    @Insert("insert into user(UserName,Password,RealName,UseType,DocTitleID,IsScheduling,DeptID,RegistLeID) values(#{userName},#{password},#{realName},#{useType},#{docTitleId},#{isScheduling},#{deptId},#{registLeId})")
    void insertUser(String userName,String password,String realName,Integer useType,Integer docTitleId,String isScheduling,Integer deptId,Integer registLeId);
    @Select("select password from user where id=#{id}")
    String getPassword(Integer id);
    @Update("update user set password=#{password} where id=#{id}")
    void updatePassword(Integer id,String password);

}
